using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace Toenda.Foundation.Globalization {
	/// <summary>
	/// Extends the CultureInfo class
	/// </summary>
	public class CultureInfoExtensions {
		/// <summary>
		/// Gets a culture info object by the ISO 6133 code list
		/// </summary>
		/// <param name="isoLanguageName"></param>
		/// <returns></returns>
		public static CultureInfo FindCulture(string isoLanguageName) {
			try {
				return new CultureInfo(isoLanguageName);
			}
			catch(Exception) {
				foreach(CultureInfo info in CultureInfo.GetCultures(CultureTypes.AllCultures)) {
					if(info.Name.ToLower().Contains(isoLanguageName)
					|| info.Name.ToLower() == isoLanguageName
					|| info.TwoLetterISOLanguageName == isoLanguageName) {
						return info;
					}
				}

				return null;
			}
		}
	}
}
